package cq.com.cn.servlet;

import com.google.gson.Gson;
import cq.com.cn.model.BooksModel;
import cq.com.cn.model.UserModel;
import cq.com.cn.service.BooksService;
import cq.com.cn.service.UserService;
import cq.com.cn.utils.AjaxUtils;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
@WebServlet("/user/register.do")
public class UserRegisterServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        UserModel user=new UserModel();
        try {
            BeanUtils.populate(user,req.getParameterMap());

            UserService userService=new UserService();

            userService.registerUser(user);

            AjaxUtils.showInfo(resp,"注册成功!","/view/login.html");

        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
